package cn.jilian.admin.tool.service.support.formatters;

import org.apache.commons.lang3.StringUtils;

import cn.jilian.admin.tool.service.support.Formatter;

public class StringFormatter implements Formatter {
	
	public static final Formatter instance=new StringFormatter();

	@Override
	public String format(Object v) {
		if(v==null)return "null";
		String value=String.valueOf(v);
		value=StringUtils.replaceAll(value, "'", "\\\\'");
		return new StringBuilder("'").append(value).append("'").toString();
	}

	@Override
	public void append(StringBuilder sb, Object v) {
		if(v==null) {
			sb.append("null");
			return;
		}
		String value=String.valueOf(v);
		value=StringUtils.replaceAll(value, "'", "\\\\'");
		sb.append("'").append(value).append("'");
	}
	
	public static void main(String[] args) {
		String v=" 'jdhsjdfj'='ssfdf'";
		v=StringUtils.replaceAll(v, "'", "\\\\'");
		System.out.println(v);
	}

}
